<template>
  <div>
    <el-button size="mini" type="text" icon="el-icon-edit" @click="printDemo()"
      >打印
      <vue-easy-print tableShow ref="easyPrint" v-show="false">
        <template>
          <printUser :tableData="tabledata"></printUser>
        </template>
      </vue-easy-print>
    </el-button>
  </div>
</template>
<script>
import vueEasyPrint from "vue-easy-print";
import printUser from "./esayPrint/index.vue";
export default {
  name: "testPrint",
  components: { vueEasyPrint, printUser },
  data() {
    return {
      tabledata: {},
    };
  },
  methods: {
    printDemo() {
      this.tabledata = [
        {
          index: "1",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "10",
          remark: "",
        },
        {
          index: "2",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "20",
          remark: "",
        },
        {
          index: "3",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "20",
          remark: "",
        },
        {
          index: "4",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "1",
          remark: "",
        },
        {
          index: "5",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "1",
          remark: "",
        },
        {
          index: "6",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "2",
          remark: "",
        },
        {
          index: "7",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "4",
          remark: "",
        },
        {
          index: "8",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "8",
          remark: "",
        },
        {
          index: "9",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "8",
          remark: "",
        },
        {
          index: "10",
          code: "123454444442",
          projectname: "载药微球",
          number: "29435947",
          price: "2500",
          count: "2",
          remark: "",
        },
      ];
      //注：此处使用延时的原因是，防止点击打印都，打印内容还未渲染到模板，导致打印页面显示空白。
      setTimeout(() => {
        this.$refs.easyPrint.print();
      }, 100);
    },
  },
};
</script>
<style scoped>
.titleDiv{
  box-sizing: border-box;
  width: 734px;
  border-top: 1px solid #000;
  border-left:1px solid #000 ;
  border-right:1px solid #000;
  text-align: left;
  height: 50px;
  line-height: 50px;
  margin: auto;
}
.titleBox{
  display: flex;
  justify-content: space-between;
}
.titleBox span{
  display: block;
  width: 20%;
}
* {
  padding: 0;
  margin: 0;
  list-style-type: none;
  /* font-family: "微软雅黑"; */
  font-size: 12px;
}

.tab_company_out {
  text-align: center;
  width: 100%;
  margin: auto;
  page-break-after: always;
}
.title{
  font-size: 25px;
  font-family: "宋体";
}
.sontitle{
  font-size: 20px;
  font-family: "黑体";
}
h3 {
  font-size: 14px;
}
.dan {
  text-align: center;
  position: relative;
}

.dan span {
  position: absolute;
  right: 0;
}
p {
  overflow: hidden;
  padding: 10px 0;
}
p span {
  float: left;
}
p span ins {
  text-decoration: underline;
}
p time {
  float: right;
}
table {
  margin-left: 20px;
  width: 95%;
  border: none;
  border-bottom: 1px solid #000;
}
table tr td {
  border: 1px solid #000;
  border-bottom: none;
  border-right: none;
  height: 20px;
  line-height: 20px;
}
table tr td:last-of-type,
table tr th:last-of-type {
  border-right: 1px solid #000;
}
table tr th {
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  height: 22px;
  line-height: 22px;
  font-size: 12px;
}
table tr th:nth-child(2) {
  width: 0;
}
.lu {
  display: inline-block;
  padding-top: 10px;
}
.lu li {
  float: left;
  text-align: left;
  margin-right: 15px;
}
.lu li label {
  width: 100px;
  display: inline-block;
}
.lu li:last-of-type {
  margin-right: 0;
}
@page {
  size: auto A4 landscape;
  margin: 3mm;
}
</style>